<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<body>
	<style>
.ui-widget,.ui-widget .ui-widget {
	font-size: 90% !important;
}
</style>
	<h:head>
	</h:head>
	<h:form>
		<p:messages id="mainmessages" globalOnly="true" redisplay="false"
			showDetail="true" autoUpdate="true" closable="true"></p:messages>
	</h:form>
	<h:form>
		<!-- Menu for admin options -->
		<p:commandButton id="adminoptions" icon="ui-icon-star"
			title="Administrator Einstellungen" />
		<p:menu overlay="true" trigger="adminoptions" my="left top"
			at="left bottom" style="width:210px">
			<p:submenu label="Benutzereinstellungen">
				<p:menuitem value="Neuen Benutzer anlegen" icon="ui-icon-person"
					action="#{adminOptionsBean.showNewUserDialog}" />
				<p:menuitem value="Benutzer löschen" icon="ui-icon-trash"
					action="#{adminOptionsBean.showDeleteUserDialog}"
					update=":deleteUserForm:deleteUser" />
				<p:menuitem value="Ein Passwort zurücksetzen"
					icon="ui-icon-unlocked"
					action="#{adminOptionsBean.showResetPasswordDialog}"
					update=":resetPasswordForm:resetPassword" />
			</p:submenu>
			<p:submenu label="Servereinstellungen">
				<p:menuitem value="SQL Server einstellen" icon="ui-icon-link"
					action="#{adminOptionsBean.showDatabaseDialog}"
					update=":databaseSettingsForm:databaseSettings" />
				<p:menuitem value="Max. Anzahl Berechnungen"
					icon="ui-icon-calculator"
					action="#{adminOptionsBean.showMaxSimDialog}"
					update=":concurrentSimForm:concurrentSim" />
			</p:submenu>
			<p:submenu label="Sonstiges">
				<p:menuitem value="Datenquellen einrichten" icon="ui-icon-document"
					action="#{adminOptionsBean.showSourceDBDialog}"
					update=":editSourceDBForm:editSourceDB" />
			</p:submenu>
		</p:menu>

		<!-- Menu for user options -->

		<p:commandButton id="options" icon="ui-icon-wrench"
			title="Einstellungen" />
		<p:menu overlay="true" trigger="options" my="left top"
			at="left bottom" style="width:210px">
			<p:submenu label="Benutzer">
				<p:menuitem value="Passwort ändern" icon="ui-icon-key"
					oncomplete="passwordDialog.show()" />
			</p:submenu>
			<p:submenu label="Berechnungen">
				<p:menuitem value="Referenzsystem" icon="ui-icon-bullet"
					oncomplete="refSysDialog.show()" />
			</p:submenu>
		</p:menu>

		<!-- Logout button -->

		<p:commandButton id="logout" ajax="false" value="Abmelden"
			action="#{loginBean.logOut}" />

	</h:form>
	<br />
	<br />

	<center>
		<h:graphicImage value="banner.png" />
	</center>

	<br />
	<!-- New Simulation button, displays the new simulation dialog-->

	<center>
		<p:commandButton value="Neue Berechnung"
			oncomplete="newSimDialog.show()" icon="ui-icon-plusthick" />
	</center>

	<!-- Datatable for simulations -->

	<h:form id="form">
		<center>

			<p:dataTable id="simTable1" var="simulation" widgetVar="simTable"
				value="#{listModel.simulations}" rowKey="#{simulation.name}"
				selection="#{listModel.selectedSimulation}" sortMode="single"
				style="width:750px"
				emptyMessage="Keine Berechnungen wurden gefunden"
				filteredValue="#{listModel.filteredSimulations}" dynamic="true">
				<f:facet name="header">
						Berechnungen  
				</f:facet>
				<p:column id="nameHeader" sortBy="#{simulation.name}">
					<f:facet name="header">
						<h:outputText value="Name" />
					</f:facet>
					<h:outputText value="#{simulation.name}" />
				</p:column>

				<p:column id="timeStampHeader" sortBy="#{simulation.timeStamp}">
					<f:facet name="header">
						<h:outputText value="Erstellt" />
					</f:facet>
					<h:outputText value="#{simulation.timeStamp}" />
				</p:column>

				<p:column id="startTimeHeader" sortBy="#{simulation.startTime}">
					<f:facet name="header">
						<h:outputText value="Startdatum" />
					</f:facet>
					<h:outputText value="#{simulation.startTime}" />
				</p:column>

				<p:column id="endTimeHeader" sortBy="#{simulation.endTime}">
					<f:facet name="header">
						<h:outputText value="Enddatum" />
					</f:facet>
					<h:outputText value="#{simulation.endTime}" />
				</p:column>

				<p:column id="colCountHeader" sortBy="#{simulation.collisionCount}">
					<f:facet name="header">
						<h:outputText value="Anzahl Kollisionen" />
					</f:facet>
					<h:outputText value="#{simulation.collisionCount}" />
				</p:column>

				<p:column style="width:4%">
					<p:column style="width:4%">
						<p:commandButton id="selectButton"
							update=":simDialogForm:simDialog1"
							action="#{chartBean.showSimDialog}"
							oncomplete="progressBar.start()" icon="ui-icon-search"
							title="Ansehen">
							<f:setPropertyActionListener value="#{simulation}"
								target="#{listModel.selectedSimulation}" />
						</p:commandButton>
					</p:column>
				</p:column>

				<p:column style="width:4%">
					<p:column style="width:4%">
						<p:commandButton id="editButton" update=":editSimForm:editSim"
							oncomplete="editSimDialog.show()" icon="ui-icon-pencil"
							title="Bearbeiten">
							<f:setPropertyActionListener value="#{simulation}"
								target="#{listModel.selectedSimulation}" />
						</p:commandButton>
					</p:column>
				</p:column>

				<p:column style="width:4%">
					<p:column style="width:4%">
						<p:commandButton id="deleteButton"
							update=":deleteSimForm:deleteSim"
							oncomplete="deleteSimDialog.show()" icon="ui-icon-close"
							title="Löschen">
							<f:setPropertyActionListener value="#{simulation}"
								target="#{listModel.selectedSimulation}" />
						</p:commandButton>
					</p:column>
				</p:column>

				<p:column style="width:4%">
					<p:column style="width:4%">
						<p:commandButton id="exportButton" update=":form:display"
							icon="ui-icon-disk" title="Exportieren" ajax="false">
							<f:setPropertyActionListener value="#{simulation}"
								target="#{listModel.selectedSimulation}" />
							<p:dataExporter type="pdf" target="simTable1"
								fileName="simulation" pageOnly="false"
								postProcessor="#{exportBean.postProcessPDF}" />
						</p:commandButton>
					</p:column>
				</p:column>

			</p:dataTable>
		</center>

		<br />
		<br />

		<br />
	</h:form>
	
	<!-- Dialog for showing the simulation details -->
	
	<h:form id="simDialogForm">
		<p:dialog header="" widgetVar="simDialog" resizable="false"
			id="simDialog1" showEffect="fade" hideEffect="fade" modal="true"
			appendToBody="true" width="700" height="550" onclose="progressBar.cancel()">
			<h:panelGrid id="display" columns="2" cellpadding="4"
				style="margin:0 auto;">
				<h:outputText value="Name:" />
				<h:outputText value="#{listModel.selectedSimulation.name}"
					style="font-weight:bold" />
				<h:outputText value="Beschreibung: " />
				<h:outputText value="#{listModel.selectedSimulation.description}"
					style="font-weight:bold" />
				<h:outputText value="Erstellt:" />
				<h:outputText value="#{listModel.selectedSimulation.timeStamp}"
					style="font-weight:bold" />
				<h:outputText value="Startdatum:" />
				<h:outputText value="#{listModel.selectedSimulation.startTime}"
					style="font-weight:bold" />
				<h:outputText value="Enddatum:" />
				<h:outputText value="#{listModel.selectedSimulation.endTime}"
					style="font-weight:bold" />
				<h:outputText value="Kollisionsabstand;" />
				<h:outputText
					value="#{listModel.selectedSimulation.collisionDistance}"
					style="font-weight:bold" />
				<h:outputText value="Referenzsystem" />
				<h:outputText
					value="#{listModel.selectedSimulation.referenceSystem}"
					style="font-weight:bold" />
				<h:outputText value="Anzahl Kollisionen:" />
				<h:outputText value="#{listModel.selectedSimulation.collisionCount}"
					style="font-weight:bold" />
				<h:outputText value="Benutzer:" />
				<h:outputText value="#{listModel.selectedSimulation.username}"
					style="font-weight:bold" />
			</h:panelGrid>
			<br />
			<center>
				<h:outputText value="Referenzdaten:" style="font-weight:bold" />
				<br />
				<p:outputPanel id="refdata" autoUpdate="true" align="left">
					<h:outputText value="#{listModel.selectedSimulation.refData}"
						escape="false" align="left" />
				</p:outputPanel>
			</center>
			<br />
			<center>
				<br />
				<p:progressBar widgetVar="progressBar" ajax="true" id="pB"
					value="#{progressbarBean.progress}" labelTemplate="{value}%"
					sinterval="5000">
				</p:progressBar>
				<br />
				<h:outputText value="Kollisionen:" style="font-weight:bold" />
				<br />
				<p:outputPanel id="results" autoUpdate="true">
					<h:outputText value="#{listModel.selectedSimulation.results}"
						escape="false" align="left" />
				</p:outputPanel>
				<br /> <br />
				<p:barChart id="graph" value="#{chartBean.categoryModel}"
					legendPosition="ne" min="0"
					max="#{listModel.selectedSimulation.refCount}" style="height:250px" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for editing an existing simulation -->
	<!-- IMPLEMENT -->

	<h:form>
		<p:dialog header="Berechnung editieren" widgetVar="simEditDialog"
			resizable="false" id="simEdit" showEffect="fade" hideEffect="fade"
			modal="true" appendToBody="true" width="500" height="500">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true"></p:messages>
			<center>
				<h:outputText value="Name:" />
				<br />
				<p:inputTextarea id="editSimName" value="#{simulationBean.name}"
					escape="false" style="width:400px;height:150px;" resizable="false"
					autoResize="false" autoUpdate="true" />
				<br />
				<p:watermark for="editSimName"
					value="Neuer Name der Simulation. Lassen sie leer um alten Namen zu behalten." />
				<br />
				<h:outputText value="Beschreibung:" />
				<br />
				<p:inputTextarea id="editSimDesc"
					value="#{simulationBean.description}" escape="false"
					style="width:400px;height:150px;" resizable="false"
					autoResize="false" autoUpdate="true" />
				<p:watermark for="editSimDesc"
					value="Neue Beschreibung der Simulation. Lassen sie leer um die alte Beschreibung zu behalten." />
				<br />
				<p:commandButton value="Ändern"
					action="#{simulationBean.changeNameAndDesc}" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Change password dialog -->

	<h:form>
		<p:dialog header="Passwort ändern" widgetVar="passwordDialog"
			resizable="false" id="changePW" showEffect="fade" hideEffect="fade"
			modal="true" width="360">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<h:panelGrid id="passwordPanel" columns="2" cellpadding="4"
				style="margin:0 auto;">
				<h:outputText value="Altes Passwort:" />
				<p:password id="oldPassword" value="#{userSettingsBean.oldPassword}" />
				<h:outputText value="Neues Passwort:" />
				<p:password id="newPassword1"
					value="#{userSettingsBean.newPassword1}" />
				<h:outputText value="Neues Passwort:" />
				<p:password id="newPassword2"
					value="#{userSettingsBean.newPassword2}" />
			</h:panelGrid>
			<br />
			<center>
				<p:commandButton value="Ändern"
					action="#{userSettingsBean.changePassword}" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Select reference system dialog -->

	<h:form>
		<p:dialog header="Referenzsystem" widgetVar="refSysDialog"
			resizable="false" id="changePW" showEffect="fade" hideEffect="fade"
			modal="true" width="360">
			<center>
				<h:outputText value="Gängige Referenzsystem: "></h:outputText>
				<h:outputText value="#{userSettingsBean.currentRefSystem}"></h:outputText>
				<br /> <br />
				<h:outputText value="Neue Referenzsystem: "></h:outputText>
				<p:selectOneListbox id="refList"
					value="#{userSettingsBean.refSystem}">
					<f:selectItem itemLabel="WGS84" itemValue="84"></f:selectItem>
					<f:selectItem itemLabel="WGS72" itemValue="72"></f:selectItem>
					<f:selectItem itemLabel="WGS721" itemValue="721"></f:selectItem>
				</p:selectOneListbox>
			</center>
			<br />
			<center>
				<p:commandButton value="OK" ajax="false"
					action="#{userSettingsBean.changeRefSystem}"></p:commandButton>
			</center>
		</p:dialog>
	</h:form>

	<!-- New Simulation Dialog -->

	<h:form>
		<p:dialog header="Neue Berechnung" widgetVar="newSimDialog"
			resizable="false" id="newSim" showEffect="fade" hideEffect="fade"
			modal="true" width="600" height="500">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<h:panelGrid id="newSimPanel1" columns="2" cellpadding="4"
				style="margin:0 auto;">
				<h:outputText value="Name der Berechnung:" />
				<p:inputText value="#{newSimulationBean.name}" />
				<h:outputText value="Beschreibung:" />
				<p:inputText value="#{newSimulationBean.description}" />
				<h:outputText value="Kollisionsabstand in km:" />
				<p:inputText value="#{newSimulationBean.collisionDistance}" />
			</h:panelGrid>
			<p:separator />
			<br />
			<center>
				<h:outputText value="Berechnungszeitraum" />
			</center>
			<h:panelGrid id="newSimPanel2" columns="2" cellpadding="4"
				style="margin:0 auto;">
				<h:outputText value="Startdatum:" />
				<p:inputText value="#{newSimulationBean.startTime}" />
				<h:outputText value="Enddatum:" />
				<p:inputText value="#{newSimulationBean.endTime}" />
			</h:panelGrid>
			<br />
			<center>
				<h:outputText value="Referenzdaten:" />
				<br />
			</center>

			<!-- File upload -->

			<p:outputPanel id="TLEPanel" autoUpdate="false">
				<center>
					<p:inputTextarea id="textTLE" value="#{newSimulationBean.referenceData}"
						escape="false" style="width:540px;height:100px;" resizable="false"
						autoResize="false" ajax="false"></p:inputTextarea>
				</center>
			</p:outputPanel>
			<p:fileUpload
				fileUploadListener="#{newSimulationBean.handleFileUpload}"
				mode="advanced" update="TLEPanel" multiple="true" sizeLimit="1000000"
				allowTypes="/(\.|\/)(cato|txt|tle)$/" oncomplete="updt()"/>
				<p:remoteCommand name="updt" update="TLEPanel"/>

			<!--  -->

			<center>
				<p:commandButton value="Fertig"
					action="#{newSimulationBean.startNewSimulation}"
					update="TLEPanel,:form:simTable1" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for creating a new user -->

	<h:form>
		<p:dialog header="Neuen Benutzer anlegen" widgetVar="newUserDialog"
			resizable="false" id="newUser" showEffect="fade" hideEffect="fade"
			modal="true" width="360">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<center>
				<p:outputLabel for="username" value="Benutzername: " />
				<p:inputText id="username" value="#{adminOptionsBean.newUsername}" />
			</center>
			<br />
			<center>
				<p:commandButton value="Benutzer hinzufügen"
					action="#{adminOptionsBean.createNewUser}"
					update=":userDetailsForm:newUserDetails" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for new user details-->

	<h:form id="userDetailsForm">
		<p:dialog header="Neuer Benutze wurde angelegt"
			widgetVar="newUserDetailsDialog" resizable="false"
			id="newUserDetails" showEffect="fade" hideEffect="fade" modal="true"
			width="360">
			<center>
				<h:outputText value="Benutzername:" style="font-weight:bold" />
				<br />
				<h:outputText value="#{adminOptionsBean.newUsername}" />
				<br /> <br />
				<h:outputText value="Passwort:" style="font-weight:bold" />
				<br />
				<h:outputText value="#{adminOptionsBean.newUserPassword}" />
				<br /> <br />
				<p:commandButton value="OK" onclick="newUserDetailsDialog.hide()" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for deleting users -->

	<h:form id="deleteUserForm">
		<p:dialog header="Benutzer löschen" widgetVar="deleteUserDialog"
			resizable="false" id="deleteUser" showEffect="fade" hideEffect="fade"
			modal="true" width="360">
			<center>
				<p:selectOneMenu value="#{adminOptionsBean.selectedUsername}"
					style="width:300px">
					<f:selectItem itemLabel="Wählen Sie einen Benutzer aus"
						itemValue="" />
					<f:selectItems value="#{adminOptionsBean.usernames}" />
				</p:selectOneMenu>
				<br /> <br />
				<p:commandButton value="Benutzer löschen"
					action="#{adminOptionsBean.showDeleteConfirm}"
					oncomplete="deleteUserDialog.hide()"
					update=":deleteUserConfirm:confirmDelete" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Confirm dialog for deleting a user -->

	<h:form id="deleteUserConfirm">
		<p:confirmDialog id="confirmDelete"
			message="Möchten Sie wirklich #{adminOptionsBean.selectedUsername} löschen?"
			header="Bestätigung" severity="alert" widgetVar="confirmDeleteDialog">

			<p:commandButton value="Ja" action="#{adminOptionsBean.deleteUser}"
				oncomplete="confirmDeleteDialog.hide()" />
			<p:commandButton value="Nein" onclick="confirmDeleteDialog.hide()"
				update=":deleteUserForm:deleteUser" />

		</p:confirmDialog>
	</h:form>

	<!-- Dialog for reseting a password -->

	<h:form id="resetPasswordForm">
		<p:dialog header="Passwort zurücksetzen"
			widgetVar="resetPasswordDialog" resizable="false" id="resetPassword"
			showEffect="fade" hideEffect="fade" modal="true" width="360">
			<center>
				<p:selectOneMenu value="#{adminOptionsBean.selectedUsername}"
					style="width:300px">
					<f:selectItem itemLabel="Wählen Sie einen Benutzer aus"
						itemValue="" />
					<f:selectItems value="#{adminOptionsBean.usernames}" />
				</p:selectOneMenu>
				<br /> <br />
				<p:commandButton value="Passwort zurücksetzen"
					action="#{adminOptionsBean.resetPassword}"
					oncomplete="resetPasswordDialog.hide()"
					update=":resetPasswordDetailsForm:resetPasswordDetails" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for reset password details -->

	<h:form id="resetPasswordDetailsForm">
		<p:dialog header="Passwort zurückgesetzt"
			widgetVar="resetPasswordDetailsDialog" resizable="false"
			id="resetPasswordDetails" showEffect="fade" hideEffect="fade"
			modal="true" width="360">
			<center>
				<h:outputText value="Neuer Passwort:" />
				<br /> <br />
				<h:outputText value="#{adminOptionsBean.newResetPassword}" />
				<br /> <br />
				<p:commandButton value="OK" onclick="resetPasswordDetails.hide()" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for database settings -->

	<h:form id="databaseSettingsForm">
		<p:dialog header="Datenbank einstellungen"
			widgetVar="databaseSettingsDialog" resizable="false"
			id="databaseSettings" showEffect="fade" hideEffect="fade"
			modal="true" width="400">
			<center>
				<h:outputText value="Name:" />
				<br /> <br />
				<p:inputText value="#{adminOptionsBean.dbName}" />
				<br /> <br />
				<h:outputText value="URL:" />
				<br /> <br />
				<p:inputText value="#{adminOptionsBean.dbUrl}" />
				<br /> <br />
				<h:outputText value="Benutzername:" />
				<br /> <br />
				<p:inputText value="#{adminOptionsBean.dbUsername}" />
				<br /> <br />
				<h:outputText value="Passwort:" />
				<br /> <br />
				<p:inputText value="#{adminOptionsBean.dbPass}" />
				<br /> <br />
				<p:commandButton value="OK"
					action="#{adminOptionsBean.editDatabaseSettings}" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for setting max. concurrent simulations -->

	<h:form id="concurrentSimForm">
		<p:dialog header="Max. Anzahl simultaner Berechnungen"
			widgetVar="concurrentSimDialog" resizable="false" id="concurrentSim"
			showEffect="fade" hideEffect="fade" modal="true" width="400">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true"></p:messages>
			<center>
				<p:inputText value="#{adminOptionsBean.maxSimulations}" />
				<br /> <br />
				<p:commandButton value="OK" action="#{adminOptionsBean.setMaxSim}" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for deleting a simulation -->

	<h:form id="deleteSimForm">
		<p:dialog header="Simulation löschen" widgetVar="deleteSimDialog"
			resizable="false" id="deleteSim" showEffect="fade" hideEffect="fade"
			modal="true" width="400">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true"></p:messages>
			<center>
				<h:outputText
					value="Wollen sie wirklich diese Berechnung löschen?
				Laufende Berechnung wird abgebrochen." />
				<br /> <br />
				<p:commandButton value="Ja"
					action="#{simulationBean.deleteSimulation}"
					update=":form:simTable1" />
				<p:commandButton value="Nein" onclick="deleteSimDialog.hide()" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for editing a simulation -->

	<h:form id="editSimForm">
		<p:dialog header="Simulation editieren" widgetVar="editSimDialog"
			resizable="false" id="editSim" showEffect="fade" hideEffect="fade"
			modal="true" width="400">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true"></p:messages>
			<center>
				<h:outputText value="Name:" />
				<br /> <br />
				<p:inputTextarea value="#{simulationBean.name}" rows="5" cols="50" />
				<br /> <br />
				<h:outputText value="Beschreibung:" />
				<br /> <br />
				<p:inputTextarea value="#{simulationBean.description}" rows="5"
					cols="50" />
				<br /> <br />
				<p:commandButton value="OK"
					action="#{simulationBean.changeNameAndDesc}"
					update=":form:simTable1" />
			</center>
		</p:dialog>
	</h:form>

	<!-- Dialog for editing source database login data -->

	<h:form id="editSourceDBForm">
		<p:dialog header="Datenquellenseiten" widgetVar="editSourceDBDialog"
			resizable="false" id="editSourceDB" showEffect="fade"
			hideEffect="fade" modal="true" width="400">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true"></p:messages>
			<center>
				<h:outputText value="SpaceTrack" style="font-weight:bold" />
				<br />
				<h:outputText value="Benutzername:" />
				<br />
				<p:inputText value="#{adminOptionsBean.spaceTrackUsername}" />
				<br /> <br />
				<h:outputText value="Passwort:" />
				<br />
				<p:password value="#{adminOptionsBean.spaceTrackPassword}" />
				<br /> <br />
				<p:commandButton value="OK"
					action="#{adminOptionsBean.setSourceDBLogins}" />
				<p:commandButton value="Abbrechen"
					onclick="editSourceDBDialog.hide()" />
			</center>
		</p:dialog>
	</h:form>
</body>
</html>
